package com.me.control;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.me.MyAppleDrop.MainAppleDrop;
import com.me.constant.Constant;
import com.me.enums.ScreenEnum;
import com.me.screen.PlayScreen;

public class CreateWindown {
	private  WindowSettingControl windowSettingControl;
	float w;
	float h;
	Group group;
	ScrollPane scroll;
	Label lb_about;
	
	public Image createBackground(){
		TextureRegionDrawable bg = new TextureRegionDrawable(MainAppleDrop.getAtlas().findRegion("datagame/bg_popup"));
		Image img = new Image(bg);
		return img;
	}
	public final Image img_backgroundHide = createBackground();
	
	public Group CreateWindown_About() {
		 group  = new Group();
			
//			final ImageButton img_X;
//			TextureRegionDrawable imgUp = new TextureRegionDrawable(atlas.findRegion("ImageNew/button_tat"));
//			TextureRegionDrawable imgDown = new TextureRegionDrawable(atlas.findRegion("ImageNew/button_tat_over"));
//			img_X = new ImageButton(imgUp, imgDown);
		windowSettingControl = new WindowSettingControl("About",MainAppleDrop.getMySkin(),
				Constant.STAGE_WIDTH - 200,
				Constant.STAGE_HEIGHT - 100);
			
		w = windowSettingControl.getWidth();
		h = windowSettingControl.getHeight();
		
		lb_about = new Label(" Apple Drop\n Version: 1.0.0 \n Pichichi", MainAppleDrop.getMySkin(), "label24");
		lb_about.setX((w - lb_about.getWidth())/2 );
		lb_about.setY(h - 200);
		lb_about.setAlignment(Align.center);
		final TextButton btn_close = new TextButton("Close", MainAppleDrop.getMySkin(), "textButton_50_1");
		btn_close.setWidth(200);
		btn_close.setX((w - btn_close.getWidth())/2);
		btn_close.setY(20);
		btn_close.addListener(new ClickListener() {
		public void touchUp(InputEvent event, float x, float y,
			int pointer, int button) {
			super.touchUp(event, x, y, pointer, button);
			group.removeActor(windowSettingControl);
			}
		});
		
		windowSettingControl.addActor(lb_about);
		windowSettingControl.addActor(btn_close);
		group.addActor(windowSettingControl);
			
		return group;
	}
	
	public Group CreateWindown_Help() {
		 group  = new Group();
			
//			final ImageButton img_X;
//			TextureRegionDrawable imgUp = new TextureRegionDrawable(atlas.findRegion("ImageNew/button_tat"));
//			TextureRegionDrawable imgDown = new TextureRegionDrawable(atlas.findRegion("ImageNew/button_tat_over"));
//			img_X = new ImageButton(imgUp, imgDown);
			windowSettingControl = new WindowSettingControl("Help",MainAppleDrop.getMySkin(),
					Constant.STAGE_WIDTH - 200,
					Constant.STAGE_HEIGHT - 100);
			
			w = windowSettingControl.getWidth();
			h = windowSettingControl.getHeight();
			
			final TextButton btn_close = new TextButton("Close", MainAppleDrop.getMySkin(), "textButton_50_1");
			btn_close.setWidth(200);
			btn_close.setX((w - btn_close.getWidth())/2);
			btn_close.setY(20);
			btn_close.addListener(new ClickListener() {
				public void touchUp(InputEvent event, float x, float y,
						int pointer, int button) {
					super.touchUp(event, x, y, pointer, button);
					group.removeActor(windowSettingControl);
				}
			});
			
			windowSettingControl.addActor(btn_close);
			group.addActor(windowSettingControl);
			
			return group;
	}
	
	public Group CreateWindow_LoseGame(){
		group = new Group();
		TextButton btn_replay = new TextButton("Replay", MainAppleDrop.getMySkin(),"textButton_50");
		btn_replay.setWidth(Constant.STAGE_WIDTH/2);
		btn_replay.setX((Constant.STAGE_WIDTH - btn_replay.getWidth())/2);
		btn_replay.setY(300);
		btn_replay.addListener(new ClickListener() {
			@Override
			public void touchUp(InputEvent event, float x, float y,
					int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				Gdx.graphics.setContinuousRendering(true);
				PlayScreen.b_check = true;
				MainAppleDrop.getScreenManager().createScreen(ScreenEnum.PLAY_SCREEN);
				MainAppleDrop.getScreenManager().getScreen().show();
			}
		});
		
		TextButton btn_MainMenu = new TextButton("Main Menu", MainAppleDrop.getMySkin(),"textButton_50");
		btn_MainMenu.setWidth(Constant.STAGE_WIDTH/2);
		btn_MainMenu.setX(btn_replay.getX());
		btn_MainMenu.setY(btn_replay.getY() - btn_MainMenu.getHeight() - 20);
		btn_MainMenu.addListener(new ClickListener() {
			@Override
			public void touchUp(InputEvent event, float x, float y,
					int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				Gdx.graphics.setContinuousRendering(true);
				PlayScreen.b_check = true;
				MainAppleDrop.getScreenManager().createScreen(ScreenEnum.MENU_SCREEN);
				MainAppleDrop.getScreenManager().getScreen().show();
			}
		});
		
		TextButton btn_Exit = new TextButton("Exit", MainAppleDrop.getMySkin(),"textButton_50");
		btn_Exit.setWidth(Constant.STAGE_WIDTH/2);
		btn_Exit.setX(btn_replay.getX());
		btn_Exit.setY(btn_MainMenu.getY() - btn_Exit.getHeight() - 20);
		btn_Exit.addListener(new ClickListener() {
			@Override
			public void touchUp(InputEvent event, float x, float y,
					int pointer, int button) {
				super.touchUp(event, x, y, pointer, button);
				Gdx.app.exit();
			}
		});
		
		img_backgroundHide.setColor(Color.MAGENTA);
		group.addActor(img_backgroundHide);
		group.addActor(btn_replay);
		group.addActor(btn_MainMenu);
		group.addActor(btn_Exit);
		return group;
	}
	
}
